//
//  OpenFaPiaoTableViewController.m
//  PropertyManager
//
//  Created by 黎世炜 on 2018/11/7.
//  Copyright © 2018年 Tng. All rights reserved.
//

#import "OpenFaPiaoTableViewController.h"
#import "NotPayDetailsModel.h"
@interface OpenFaPiaoTableViewController ()
@property (weak, nonatomic) IBOutlet UITextField *titleTF;
@property (weak, nonatomic) IBOutlet UITextField *shuiHaoTF;
@property (weak, nonatomic) IBOutlet UITextField *emailTF;
@property (weak, nonatomic) IBOutlet UITextField *psTF;
@property (weak, nonatomic) IBOutlet UILabel *jinELabel;

@end

@implementation OpenFaPiaoTableViewController

-(instancetype)init{
    if (self = [super init]) {
        self = [[UIStoryboard storyboardWithName:@"NotPayListStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"OpenFaPiaoTableViewController"];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.jinELabel.text = [NSString stringWithFormat:@"¥%.lf",self.model.money];
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)clickUpload:(UIButton *)sender {
    if (!self.titleTF.text.length || !self.emailTF.text.length || !self.psTF.text.length || !self.shuiHaoTF.text.length) {
//        [MBProgressHUD showErrorWithMessage:@"请填写完整信息"];
        [SVProgressHUD ShowErrorMessage:@"请填写完整信息"];
        return;
    }
    NSMutableArray * tempArr = [NSMutableArray array];
    for (NSDictionary * dict in self.model.list) {
        NotPayDetailsModel * itemModel = [NotPayDetailsModel yy_modelWithDictionary:dict];
        NSDictionary * tempDict = @{
                                    @"xmmc":itemModel.faretype,
                                    @"xmdj":itemModel.nyreceivable,
                                    @"xmje":itemModel.nyreceivable
                                    };
        [tempArr addObject:tempDict];
    }
    NSDictionary * params = @{@"kphjje":@(self.model.money),
                              @"ghfMc":self.titleTF.text,
                              @"ghfEmail":self.emailTF.text,
                              @"bz":self.psTF.text,
                              @"gbfNsrsbh":self.shuiHaoTF.text,
                              @"gbElectronicedetailList":tempArr
                              };
//    WeakSelf
    [[HTTPClient shareClient] requestWithPath:@"/rest/gbElectroniceController/add" AndParams:params AndReturnBlock:^(NSDictionary *dic) {
        [SVProgressHUD ShowSuccessMessage:@"申请成功"];
        [self.navigationController popViewControllerAnimated:YES];
    } AndFailMessage:^(NSString *message, NSString *errorCode) {
        
    }];
}

#pragma mark - Table view data source

//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//#warning Incomplete implementation, return the number of sections
//    return 0;
//}
//
//- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//#warning Incomplete implementation, return the number of rows
//    return 0;
//}

/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
    
    // Configure the cell...
    
    return cell;
}
*/

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
